<template>
  <div class="main-container">
    <div class="main-header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{path: '/partner/classify'}">品牌案例分类管理</el-breadcrumb-item>
        <el-breadcrumb-item>新增品牌案例分类</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="wrap">
      <div class="content">
        <el-form class="mt-30" ref="form" :model="form" label-width="150px" style="width: 450px;">
          <el-form-item label="分类名称" prop="courseName" :rules="[ { required: true, message: '分类名称不能为空'}]">
            <el-input v-model="form.courseName"></el-input>
          </el-form-item>
          <el-form-item label="排序" prop="sort">
              <div class="help-tip el-iconhelp_tip element-icons" style="left: -62px;">
                <p class="help-tip-content">页面中可以通过“排序”进行升序排序。</p>
              </div>
              <el-input-number v-model="form.sort" :min="0" :controls="false"></el-input-number>
            </el-form-item>
            <el-form-item label="标题" prop="seoTitle">
            <el-input v-model="form.seoTitle" type="textarea"></el-input>
          </el-form-item>
          <el-form-item label="描述" prop="seoDesc">
            <el-input v-model="form.seoDesc" type="textarea"></el-input>
          </el-form-item>
          <el-form-item label="关键字" prop="seoKeyword">
            <el-input v-model="form.seoKeyword" type="textarea"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">保存</el-button>
            <el-button @click="onReset">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        form: {
          courseName: ''
        },
        courseList: []
      }
    },
    activated() {
      this.loadData()
    },
    created() {
      this.loadData()
    },
    methods: {
      loadData() {
        const params = {
          courseLevel: 1,
          documentType: 2
        }
        this.$api.courseType.getList(params).then(res => {
          if(res.success){
            if(res.data[0]){
              this.parentCode = res.data[0].courseCode
            } else {
              this.$router.replace('/partner/classify')
            }
          }
        })
      },
      onSubmit() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            const params = {
              ...this.form,
              parentCode: this.parentCode,
              courseLevel: 2,
              documentType: 2
            }
            this.$api.courseType.add(params).then(res => {
              if(res.success) {
                this.$message.success('保存成功')
                this.$refs.form.resetFields()
                this.$router.push('/partner/classify');
              }
            })
          }
        })
      },
      onReset() {
        this.$refs.form.resetFields()
      }
    }
  }
</script>

<style>

 
</style>
